(function(){"use strict";BX.namespace("BX.Landing");BX.Landing.Cookies=function(e){this.storageKey="bxCookies-v34";this.storage=window.localStorage;this.currentStorage=this.storage;this.enable=e.enable===true;this.onlyInformation=e.onlyInformation===true;this.siteId=parseInt(e.siteId);this.availableCodes=e.availableCodes||[];this.idButtonOpt=e.idButtonOpt||"bx-landing-cookies-opt";this.idButtonOptLink=e.idButtonOptLink||"bx-landing-cookies-opt-link";this.idButtonAccept=e.idButtonAccept||"bx-landing-cookies-accept";this.idAgreementPopup=e.idAgreementPopup||"bx-landing-cookies-popup";this.idCookiesNotice=e.idCookiesNotice||"bx-landing-cookies-popup-notice";this.idAgreementSmallPopup=e.idAgreementSmallPopup||"bx-landing-cookies-popup-warning";this.classNameMainAgreement=e.classNameMainAgreement||"bx-landing-cookies-main-agreement";this.classNameAnalyticAgreements=e.classNameAnalyticAgreements||"bx-landing-cookies-system-agreements";this.classNameTechnicalAgreements=e.classNameTechnicalAgreements||"bx-landing-cookies-technical-agreements";this.classNameOtherAgreements=e.classNameOtherAgreements||"bx-landing-cookies-other-agreements";this.classNameButtonSave=e.classNameButtonSave||"bx-landing-cookies-button-save";this.classNameButtonCancel=e.classNameButtonCancel||"bx-landing-cookies-button-cancel";this.classNameButtonClose=e.classNameButtonClose||"bx-landing-cookies-button-close";this.classNameCookiesSwitcher=e.classNameCookiesSwitcher||"bx-landing-cookies-switcher";this.messages=e.messages||{};this.agreementAjaxPath=e.agreementAjaxPath||"/";this.overlay=BX.create("div",{attrs:{className:"bx-landing-cookies-popup-overlay"}});this.cookiesNotice=BX(this.idCookiesNotice);this.acceptedAgreements={};this.agreementsChckRefs={};this.popupModified=false;this.popupInited=false;this.dataLoaded=false;this.idMainAgreementContainer=null;this.idAnalyticAgreementsContainer=null;this.idTechnicalAgreementsContainer=null;this.idOtherAgreementsContainer=null;this.idButtonSave=null;this.idButtonCancel=null;this.idButtonClose=null;this.idButtonSwitcher=null;if(!this.enable){this.enableAllCookies()}else{if(BX(this.idButtonOpt)&&BX(this.idAgreementPopup)){BX.bind(BX(this.idButtonOpt),"click",BX.delegate(this.openPopup,this))}if(BX(this.idButtonOptLink)&&BX(this.idAgreementPopup)){BX.bind(BX(this.idButtonOptLink),"click",BX.delegate(this.openPopup,this))}if(BX(this.idButtonAccept)){BX.bind(BX(this.idButtonAccept),"click",BX.delegate(this.enableAllCookies,this))}if(this.cookiesNotice){BX.bind(this.cookiesNotice,"mouseenter",BX.delegate(this.showCookiesNoticeText,this));BX.bind(this.cookiesNotice,"mouseleave",BX.delegate(this.hideCookiesNoticeText,this));BX.bind(this.cookiesNotice,"click",BX.delegate(this.openPopup,this))}this.actualizeFromStorage()}};BX.Landing.Cookies.prototype={getAvailableHooks:function(){var e=[];this.availableCodes.map(function(t){if(!BX.util.in_array(t,e)){e.push(t)}});return e},enableAllCookies:function(){var e=this.getAvailableHooks();this.setStorage(e);this.hideSmallPopup();this.showCookiesNotice()},disableAllCookies:function(){this.setStorage([])},actualizeFromStorage:function(){var e=this.getStorage(true);if(e!==null){this.showCookiesNotice()}else{this.showSmallPopup()}this.fireEvent(e||[])},initializePopup:function(){if(this.popupInited){return}this.popupInited=true;if(this.classNameMainAgreement){if(BX(this.idAgreementPopup)){this.idMainAgreementContainer=BX(this.idAgreementPopup).querySelector("."+this.classNameMainAgreement);this.idAnalyticAgreementsContainer=BX(this.idAgreementPopup).querySelector("."+this.classNameAnalyticAgreements);this.idTechnicalAgreementsContainer=BX(this.idAgreementPopup).querySelector("."+this.classNameTechnicalAgreements);this.idOtherAgreementsContainer=BX(this.idAgreementPopup).querySelector("."+this.classNameOtherAgreements);this.idButtonClose=BX(this.idAgreementPopup).querySelector("."+this.classNameButtonClose);this.idButtonSave=BX(this.idAgreementPopup).querySelector("."+this.classNameButtonSave);this.idButtonCancel=BX(this.idAgreementPopup).querySelector("."+this.classNameButtonCancel);this.idButtonSwitcher=[].slice.call(BX(this.idAgreementPopup).querySelectorAll("."+this.classNameCookiesSwitcher))}if(this.idButtonClose){BX.bind(BX(this.idButtonClose),"click",BX.delegate(this.onClickCloseIcon,this))}if(this.idButtonSave){BX.bind(BX(this.idButtonSave),"click",BX.delegate(this.savePopup,this))}if(this.idButtonCancel){BX.bind(BX(this.idButtonCancel),"click",BX.delegate(this.cancelPopup,this))}if(this.idButtonSwitcher){this.idButtonSwitcher.map(function(e){BX.bind(BX(e),"click",this.switchAgreements.bind(this,BX.data(BX(e),"type")))}.bind(this))}}},loadAgreements:function(){if(!this.idMainAgreementContainer||this.dataLoaded){this.initCheckboxes();return}this.idMainAgreementContainer.innerHTML="...";BX.ajax({url:this.agreementAjaxPath+"?action=landing.api.cookies.getAgreements",method:"POST",dataType:"json",data:{siteId:this.siteId},onsuccess:function(e){if(!e.data){return}this.dataLoaded=true;if(e.data["main"]){this.idMainAgreementContainer.innerHTML=e.data["main"]["AGREEMENT_TEXT"]}var t=false;if(e.data["analytic"]&&this.idAnalyticAgreementsContainer){t=true;this.buildAgreements(this.idAnalyticAgreementsContainer,e.data["analytic"])}else if(this.idAnalyticAgreementsContainer){BX.hide(this.idAnalyticAgreementsContainer.parentNode)}if(e.data["technical"]&&this.idTechnicalAgreementsContainer){t=true;this.buildAgreements(this.idTechnicalAgreementsContainer,e.data["technical"])}else if(this.idTechnicalAgreementsContainer){BX.hide(this.idTechnicalAgreementsContainer.parentNode)}if(e.data["other"]&&this.idOtherAgreementsContainer){t=true;this.buildAgreements(this.idOtherAgreementsContainer,e.data["other"])}else if(this.idOtherAgreementsContainer){BX.hide(this.idOtherAgreementsContainer.parentNode)}if(t){this.initCheckboxes()}}.bind(this)})},openPopup:function(){this.initializePopup();if(BX(this.idAgreementPopup)){BX.show(BX(this.idAgreementPopup));this.showOverlay();this.hideSmallPopup();this.loadAgreements()}},closePopup:function(){this.setPopupModified(false);if(BX(this.idAgreementPopup)){this.hideOverlay();BX.hide(BX(this.idAgreementPopup))}this.hideSmallPopup();this.showCookiesNotice()},savePopup:function(){if(this.popupModified){var e=this.getAcceptedAgreements();this.setStorage(e)}else{this.enableAllCookies()}this.closePopup()},cancelPopup:function(){if(this.popupModified){var e=this.currentStorage;this.setStorage(e)}else{this.disableAllCookies()}this.showSmallPopup();this.closePopup()},onClickCloseIcon:function(){this.closePopup()},setPopupModified:function(e){this.popupModified=e;if(this.idButtonSave){this.idButtonSave.textContent=this.popupModified?this.messages.acceptModified:this.messages.acceptAll}if(this.idButtonCancel){this.idButtonCancel.textContent=this.popupModified?this.messages.declineModified:this.messages.declineAll}},getStorage:function(e){var t=this.storage.getItem(this.storageKey);if(t){t=JSON.parse(t)}if(e===true){return t}return t||[]},setStorage:function(e){this.fireEvent(e);this.storage.setItem(this.storageKey,JSON.stringify(e));BX.ajax({url:this.agreementAjaxPath+"?action=landing.api.cookies.acceptAgreements",method:"POST",dataType:"json",data:{siteId:this.siteId,accepted:e}})},fireEvent:function(e){BX.onCustomEvent("BX.Landing.Cookies:onAccept",[e])},switchAgreements:function(e){if(!this.idButtonSwitcher){return}var t={};this.idButtonSwitcher.map(function(e){var i=BX(e).getAttribute("data-type");t[i]=BX(e).getAttribute("data-state")==="true"});var i=t[e]===true;for(var s in this.agreementsChckRefs){var n=BX.UI.Switcher.getById(s);if(n){var o=n.getNode().getAttribute("data-type");if(o===e){n.check(i);this.acceptAgreement(s,i)}}}this.actualizeAgreementsSwitcher();this.setPopupModified(true)},actualizeAgreementsSwitcher:function(){if(this.idButtonSwitcher){var e={};for(var t in this.agreementsChckRefs){var i=BX.UI.Switcher.getById(t);if(i){var s=i.getNode().getAttribute("data-type");if(i.isChecked()){e[s]=true}}}this.idButtonSwitcher.map(function(t){var i=BX.data(BX(t),"type");if(e[i]===true){BX(t).textContent=this.messages.switcherOff;BX(t).setAttribute("data-state",false)}else{BX(t).textContent=this.messages.switcherOn;BX(t).setAttribute("data-state",true)}}.bind(this))}},acceptAgreement:function(e,t){this.acceptedAgreements[e]=t},getAcceptedAgreements:function(){var e=[];for(var t in this.acceptedAgreements){if(this.acceptedAgreements[t]===true){e.push(t)}}return e},initCheckboxes:function(){var e=this.getStorage();this.currentStorage=this.getStorage();for(var t in this.agreementsChckRefs){var i=BX.UI.Switcher.getById(t);if(i){var s=BX.util.in_array(t,e)||i.getNode().getAttribute("data-type")!=="analytic";i.check(s);this.acceptAgreement(t,s)}}this.actualizeAgreementsSwitcher()},buildAgreements:function(e,t){var i=[];for(var s in t){this.agreementsChckRefs[s]=BX.create("span",{attrs:{className:"ui-switcher ui-switcher-size-sm","data-type":t[s]["TYPE"],"data-switcher":'{"id":"'+s+'"}'},events:{click:function(e){this.acceptAgreement(e,!BX.UI.Switcher.getById(e).isChecked());this.setPopupModified(true);setTimeout(function(){this.actualizeAgreementsSwitcher()}.bind(this),0)}.bind(this,s)}});i.push(BX.create("div",{attrs:{className:"bx-landing-cookies-analytics-block"+(t[s]["TYPE"]!=="analytic"?" bx-landing-cookies-analytics-block-disabled":"")},children:[BX.create("div",{attrs:{className:"bx-landing-cookies-analytics-header"},children:[BX.create("div",{attrs:{className:"bx-landing-cookies-analytics-title"},html:t[s]["TITLE"]}),this.agreementsChckRefs[s]]}),BX.create("div",{attrs:{className:"bx-landing-cookies-analytics-content"},html:t[s]["CONTENT"]})]}))}e.appendChild(BX.create("div",{children:i}));BX.UI.Switcher.initByClassName()},showCookiesNotice:function(){if(BX(this.idAgreementSmallPopup)&&!this.onlyInformation){this.cookiesNotice.style.display="flex"}},showCookiesNoticeText:function(){this.cookiesNotice.classList.add("bx-landing-cookies-popup-notice-full");var e=this.cookiesNotice.querySelector(".bx-landing-cookies-popup-notice-text").offsetWidth;this.cookiesNotice.style.width=this.cookiesNotice.offsetWidth+e+"px"},hideCookiesNoticeText:function(){this.cookiesNotice.style.width="27px";this.cookiesNotice.classList.remove("bx-landing-cookies-popup-notice-full")},showOverlay:function(){document.body.append(this.overlay)},hideOverlay:function(){this.overlay.remove()},showSmallPopup:function(){if(BX(this.idAgreementSmallPopup)){BX(this.idAgreementSmallPopup).style.display="block"}},hideSmallPopup:function(){if(BX(this.idAgreementSmallPopup)){BX(this.idAgreementSmallPopup).style.display="none"}}}})();
//# sourceMappingURL=script.map.js